const router = require('koa-router')();
const config = require('../config/config.local');

const listOrders = require('./orders/listOrders');
const listInventory = require('./inventory/listInventory');
const listFinances = require('./finances/listFinances');

router.use('', listOrders.routes(), listOrders.allowedMethods());
router.use('', listInventory.routes(), listInventory.allowedMethods());
router.use('', listFinances.routes(), listFinances.allowedMethods());

router.get('/', async (ctx, next) => {
  await ctx.render('index', {
    title: 'Hello Koa 2! from pt-core-operation'
  })
});

router.get('/ver', async (ctx, next) => {
  const deploymentVersion = config.ver;
  ctx.body = `welcome, deployment version: ${deploymentVersion}`;
});

router.get('/json', async (ctx, next) => {
  const data = {
    name: "product_name",
      SKU: "ABC"
  };
  ctx.response.status = 200;
  ctx.response.body = {
    title: 'koa2 json',
      data: data,
  }
});

module.exports = router;
